package com.jcsz.gulimall.search.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @className: ThreadTestCase
 * @author: 一把Po吉他
 * @date: 2022/11/6 8:27
 * @version: 1.0
 **/
public class ThreadTestCase {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main start~~");
        FutureTask futureTask = new FutureTask(new Callable() {
            @Override
            public Object call() throws Exception {

                return 1;
            }
        });
        new Thread(futureTask).start();
        Object o = futureTask.get();
        System.out.println(o);
        System.out.println("main end~~");
        System.out.println("-------------------------------------");
        FutureTask futureTask2 = new FutureTask(new Runnable() {
            @Override
            public void run() {
                System.out.println("xxxxxxx");
            }
        }, "hh");
        new Thread(futureTask2).start();
        Object o1 = futureTask2.get();
        System.out.println(o1);
        System.out.println("main end~~");
    }
}
